package mygui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class MouseDemo extends JFrame implements MouseMotionListener {
	JPanel p;
	int x,y;
	
	public MouseDemo() {
		p = new JPanel();
		p.addMouseMotionListener(this);
		this.add(p);
		this.setBounds(200,200,400,500);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	public static void main(String[] args) {
		MouseDemo f = new MouseDemo();
		f.setVisible(true);

	}
	
	@Override
	public void paint(Graphics g) {
		g.setColor(Color.RED);
		g.fillOval(x, y, 20, 20);
	}

	@Override
	public void mouseDragged(MouseEvent e) {
		x = e.getX();
		y = e.getY();
		this.repaint();
		
	}

	@Override
	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

}
